//请求绝对路径地址
var urlPath = "http://127.0.0.1:8003";
//editormd请求地址
var mdurlPath = "http://127.0.0.1";
var randomAvatar=[
	'https://unsplash.it/100/100?image=10',
	'https://unsplash.it/100/100?image=100',
	'https://unsplash.it/100/100?image=1002',
	'https://unsplash.it/100/100?image=1003',
	'https://unsplash.it/100/100?image=1005',
	'https://unsplash.it/100/100?image=1006',
	'https://unsplash.it/100/100?image=101',
	'https://unsplash.it/100/100?image=1010',
	'https://unsplash.it/100/100?image=1011',
	'https://unsplash.it/100/100?image=1012',
]

function Random(x,y){
	 return parseInt(Math.random() * (x - y + 1) + y);
}

$(function() {
	$.ajaxSetup({
		beforeSend: function(xhr) {
			xhr.setRequestHeader('token', window.sessionStorage.getItem('myblog'));
		},
		complete: function(xhr) {
			var refreshToken = xhr.getResponseHeader('refreshToken');
			if(refreshToken != null && refreshToken != undefined){
				xhr.setRequestHeader('token', refreshToken);
			}
			//			if(xhr.responseJSON.code === -1 && xhr.responseJSON.msg === '请登录') {
			//				window.location.href = "login.html";
			//			};
		}
	});
})

function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for(var i = 0; i < vars.length; i++) {
		var pair = vars[i].split("=");
		if(pair[0] == variable) {
			return pair[1];
		}
	}
	return(false);
}

function checkRequired(param) {
	for(var key in param) {
		if($('#' + key).hasClass('Required') && $('#' + key).val().trim() == '') {
			$('#checkForm').show();
			return;
		} else {
			$('#checkForm').hide();
		}
	}
}

function propSuccess(res, callback) {
	layer.msg(res.msg, {
		offset: 'rb',
		icon: 1,
		area: ['270px', '70px'],
		time: 3000
	}, callback)
}

function propFailReload(res, callback) {
	layer.msg(res.msg, {
		offset: 'rb',
		icon: 2,
		area: ['270px', '70px'],
		time: 3000
	}, callback)
}

function getCookie(key) {
	var val = "";
	// 对cookie操作
	var cookies = document.cookie;
	cookies = cookies.replace(/\s/, "");
	var cookie_array = cookies.split(";");
	for(i = 0; i < cookie_array.length; i++) {
		// yh_mch=lilei
		var cookie = cookie_array[i];
		var array = cookie.split("=");
		if(array[0].trim() == key) {
			val = array[1];
		}
	}
	return val;
}

function clearAllCookie() {
	var keys = document.cookie.match(/[^ =;]+(?=\=)/g);
	if(keys) {
		for(var i = keys.length; i--;) {
			$.cookie(keys[i], null, {
				path: '/',
				expires: -1
			});
		}
	}
}

function toBlogDetail(id) {
	window.open('/blog-page/blog.html?id=' + id + '');
}